/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - geometry/containment
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AEStaticSubmeshInstance.h
// Author:		Gianluca Belardelli
// Date:		19/06/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESTATICSUBMESHINSTANCE_H_
#define _AESTATICSUBMESHINSTANCE_H_

/// \brief
///   Class representing a renderable subset of a static mesh instance (AEStaticMeshInstance).
/// 
/// Unlike mesh instances, submesh instances may only use a single material ("surface") and a
/// single lightmap. Each submesh has to be renderable with a single graphics API rendering call
/// and may only reference a range of up to 32767 vertices in the static mesh instance.
/// 
/// Each submesh instance references a submesh (AEStaticSubmesh).
/// 
/// All the visibility determination and rendering is performed on AEStaticSubmeshInstance
/// objects, NOT on AEStaticMeshInstance objects. Thus, it is possible that only part of a
/// AEStaticMeshInstance is considered visible and is therefore rendered.
/// 
/// AEStaticSubmeshInstance objects can not be created directly, but are implicitly created
/// upon a call to AEStaticMesh::CreateInstance as part of the AEStaticMeshInstance.
/// 
/// Note that, unlike for scene elements derived from VisObject3D_cl, visibility zone assignment
/// will have to be done manually for AEStaticSubmeshInstance objects.
class AEStaticSubmeshInstance : public AEStaticGeometryInstance
{
// Members
private:
	friend class AEStaticMeshInstance;
	friend class AEStaticMesh;
	
	AEStaticSubmesh 		*m_lpSubmesh;
	AEStaticMeshInstance 	*m_lpMeshInstance;

// Methods
private:
	AE_DECLARE_PLACEMENT_ALLOCATOR();
	AEStaticSubmeshInstance( void );

public:
	/// \brief Virtual destructor of a static submesh instance.
	AE_DLLIMPEXP virtual ~AEStaticSubmeshInstance( void );
	
	/// \brief Returns a pointer to the submesh this instance was created from.
	AE_FORCEINLINE AEStaticSubmesh *GetSubmesh( void ) const;
	
	/// \brief Returns a pointer to the static mesh instance this submesh instance is part of.
	AE_FORCEINLINE AEStaticMeshInstance *GetMeshInstance( void ) const;
	
	//AE_DLLIMPEXP virtual AEINT32 TraceTest( const AEVector3f &vcStartOfLine, const AEVector3f &vcEndOfLine, AEINT32 nStoreResultCount=0, VisTraceLineInfo_t *pFirstTraceInfo=AENULL);
	
	AE_DLLIMPEXP virtual void ComputeSortingKey( void );  
	
	AE_DLLIMPEXP virtual AEINT32 GetNumPrimitives( void );
	
	AE_DLLIMPEXP virtual AEINT32 GetSupportedStreamMask( void );
	
	AE_DLLIMPEXP virtual void DebugRenderCollisionMesh( AEColor crMeshColor, AEColor crNormalColor, AEFLOAT32 fNormalLength );
	
	//AE_DLLIMPEXP virtual IVisZone_cl *GetParentZone(); 
	AE_DLLIMPEXP virtual void Render( void );
};

#include "AEStaticSubmeshInstance.inl"

#endif // _AESTATICSUBMESHINSTANCE_H_
